/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.academico.modelo;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Tatiana
 */
@Entity
@Table(catalog = "academico", schema = "public")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Curso.findAll", query = "SELECT c FROM Curso c"),
    @NamedQuery(name = "Curso.findByCurso", query = "SELECT c FROM Curso c WHERE c.curso = :curso"),
    @NamedQuery(name = "Curso.findByNombre", query = "SELECT c FROM Curso c WHERE c.nombre = :nombre")})
public class Curso implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private Integer curso;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(nullable = false, length = 100)
    private String nombre;
    @JoinTable(name = "logros_por_cursos", joinColumns = {
        @JoinColumn(name = "curso_curso", referencedColumnName = "curso", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "secuencia_logros", referencedColumnName = "secuencia", nullable = false)})
    @ManyToMany
    private Collection<Logros> logrosCollection;
    @JoinTable(name = "cursos_por_docentes", joinColumns = {
        @JoinColumn(name = "curso_curso", referencedColumnName = "curso", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "secuencia_docentes", referencedColumnName = "secuencia", nullable = false)})
    @ManyToMany
    private Collection<Docentes> docentesCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "curso")
    private Collection<Estudiantes> estudiantesCollection;
    @JoinColumn(name = "grupo", referencedColumnName = "grupo", nullable = false)
    @ManyToOne(optional = false)
    private Grupos grupo;

    public Curso() {
    }

    public Curso(Integer curso) {
        this.curso = curso;
    }

    public Curso(Integer curso, String nombre) {
        this.curso = curso;
        this.nombre = nombre;
    }

    public Integer getCurso() {
        return curso;
    }

    public void setCurso(Integer curso) {
        this.curso = curso;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    @XmlTransient
    public Collection<Logros> getLogrosCollection() {
        return logrosCollection;
    }

    public void setLogrosCollection(Collection<Logros> logrosCollection) {
        this.logrosCollection = logrosCollection;
    }

    @XmlTransient
    public Collection<Docentes> getDocentesCollection() {
        return docentesCollection;
    }

    public void setDocentesCollection(Collection<Docentes> docentesCollection) {
        this.docentesCollection = docentesCollection;
    }

    @XmlTransient
    public Collection<Estudiantes> getEstudiantesCollection() {
        return estudiantesCollection;
    }

    public void setEstudiantesCollection(Collection<Estudiantes> estudiantesCollection) {
        this.estudiantesCollection = estudiantesCollection;
    }

    public Grupos getGrupo() {
        return grupo;
    }

    public void setGrupo(Grupos grupo) {
        this.grupo = grupo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (curso != null ? curso.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Curso)) {
            return false;
        }
        Curso other = (Curso) object;
        if ((this.curso == null && other.curso != null) || (this.curso != null && !this.curso.equals(other.curso))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.academico.dao.Curso[ curso=" + curso + " ]";
    }
    
}
